home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: Jeff Grossman <grossman@teleport.com>
- Newsgroups: comp.lang.c++
- Subject: Structure member offsets at compile time - help!
- Date: 6 Feb 1996 06:02:13 GMT
- Organization: Teleport - Portland's Public Access (503) 220-1016
- Message-ID: <4f6qt5$d16@maureen.teleport.com>
- NNTP-Posting-Host: ip-pdx16-19.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
-
- I'm looking for a way to get an int offset to a structure member
- at compile time.
-
- The reason is that I need to build a table of addresses of structure
- members (if you must know, its for simplifying the process of doing
- hundreds of ODBC SQLBindCol calls).
-
- Right now I can create a table with addresses that point to a structure
- on the stack. I cannot use a static structure or a heap structure
- for these reasons:
-
- 1) if the structure is static, it is not thread safe. If I protect
- it with a critical section, it introduces too much serialization into
- the application
-
- 3) if the structure is on the heap, there is no way to create a compile
- time table (if I could figure that one out, I wouldn't need to post
- this question <g>! )
-
- The drawback to the existing method is the huge amount of code generated
- to fill this structure at each procedure entry, If I had a compile
- time static structure with int offsets, I could add in the actual
- structure address as I needed.
-
- Unfortunately, nothing I've tried works. I even tried a kludges such as:
-
- (char)(&Struc.item) - (char)(&Struc)
-
- This gives me int offsets. However, the compiler is not smart enough
- (even with optimization) to figure out that this is a compile time
- constant and generates code to do the pointer arithmetic.
-
- Does anyone know a trick to get compile time structure offsets?
-
- TIA.
-
- Jeff
-
-
-